import { each, throttle, debounce, getType } from '@antv/util';

export default G6 => {
  G6.registerBehavior('select-node', {
    selectionNode: null,
    getDefaultCfg() {
      return {
        multiple: false,
      };
    },

    getEvents() {
      return {
        'node:click': 'click',
        'canvas:click': 'clearAllSelected',
      };
    },

    shouldBegin(e) { return true; },

    click(e) {
      if (!this.shouldBegin(e)) return;

      // e.item.toFront();
      // const bool = e.item.hasState('selected');

      // this.clearAllSelected(false);

      // e.item.setState('selected', !bool);
      // this.graph.emit('node-click', { item: e.item, model: e.item.getModel() });
      // this.selectionNode = e.item.getModel();
    },

    clearAllSelected(e) {
      const { graph } = this;
      const selectedNodes = graph.findAllByState('node', 'selected');

      each(selectedNodes, node => {
        node.clearStates(['selected']);
      });

      e && graph.emit('node-click-clear')

    }

  });
};
